# Maintainer: Rémi BERTHO <remi.bertho@openmailbox.org>

_realname=muparser
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.3.2
pkgrel=1
pkgdesc="A fast math parser library (mingw-w64)"
arch=('any')
url="http://muparser.beltoforion.de/"
license=('custom')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake")
options=('!makeflags')
source=("${_realname}-${pkgver}.tar.gz"::https://github.com/beltoforion/muparser/archive/v${pkgver}.tar.gz
        "CMakeLists.txt"
        "001-exports.patch")
sha256sums=('b35fc84e3667d432e3414c8667d5764dfa450ed24a99eeef7ee3f6647d44f301'
            'dba41d1ed5b7b0aadcacd6e7f2433df844e5e9e7cabdfa7142fb7c13acae8162'
            'f125ce80b250e59a6d650cfecc11f511703a7e5079409bc287f43b3fd56cdc37')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  cp "${srcdir}/CMakeLists.txt" .
  patch -p1 -i ${srcdir}/001-exports.patch
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ../${_realname}-${pkgver}

  make
}

package() {
  cd build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install

  # license
  install -D -m644 ${srcdir}/${_realname}-${pkgver}/License.txt \
  ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
